<?php
/**
 * Created by PhpStorm.
 * User: madong
 * Date: 2018/10/12
 * Time: 9:11 PM
 */

namespace app\api\controller\jiaoyi;


use think\Config;
use think\Controller;
use think\Db;
use think\Request;
use app\api\model\Jiaoyibuylog;

class Changwaiusermanages extends Controller
{
    /*
     * 订单管理
     *
     * 参数
     *
     * @uname  当前用户名
     *
     * @orderzt  订单状态 0未付款 1已付款 2已发货 3以确认收货 4订单取消
     *
     * 返回
     *
     * 返回条件查询的所有订单
     *
     */
    public function Get_user_order(){

        $res = Request::instance();

        $Jiaoyi_log_Obj = new Jiaoyibuylog();

        $order_data = $Jiaoyi_log_Obj->where('oname|uname',$res->param('uname'))->where('oorderzt','<',2)->order('id desc')->select();

        static $data_arr = array();

        foreach ($order_data as $value){

            $arr = array();
            $arr['id'] = $value['id'];
            $arr['uid'] = $value['uid'];
            $arr['uname'] = $value['uname'];
            $arr['unickname'] = $value['unickname'];
            $arr['utruename'] = $value['utruename'];
            $arr['utx'] = $value->Uuserinfo->headimg;
            $arr['utxurl'] = $value->Uuserinfo->headimg;
            $arr['ucnynum'] = $value['ucnynum'];
            $arr['ucoinnum'] = $value['ucoinnum'];
            $arr['ufukuanfs'] = $value['ufukuanfs'];
            $arr['ubizhong'] = $value['ubizhong'];
            $arr['uordernumber'] = $value['uordernumber'];
            $arr['uorderzt'] = $value['uorderzt'];
            $arr['ubeizhu'] = $value['ubeizhu'];
            $arr['ushensu'] = $value['ushensu'];
            $arr['ushensuzt'] = $value['ushensuzt'];
            $arr['oid'] = $value['oid'];
            $arr['oname'] = $value['oname'];
            $arr['onickname'] = $value['onickname'];
            $arr['otruename'] = $value['otruename'];
            $arr['otx'] = $value->Ouserinfo->headimg;
            $arr['otxurl'] = $value->Ouserinfo->headimg;
            $arr['ocnynum'] = $value['ocnynum'];
            $arr['ocoinnum'] = $value['ocoinnum'];
            $arr['obizhong'] = $value['obizhong'];
            $arr['ofukuanfs'] = $value['ofukuanfs'];
            $arr['ouordernumber'] = $value['ouordernumber'];
            $arr['oorderzt'] = $value['oorderzt'];
            $arr['obeizhu'] = $value['obeizhu'];
            $arr['oshensu'] = $value['oshensu'];
            $arr['oshensuzt'] = $value['oshensuzt'];
            $arr['ordertype'] = $value['ordertype'];
            $arr['ordersm'] = $value['ordersm'];
            $arr['zfbzh'] = $value['zfbzh'];
            $arr['zfbimg'] = $value['zfbimg'];
            $arr['wxzh'] = $value['wxzh'];
            $arr['wximg'] = $value['wximg'];
            $arr['ylzh'] = $value['ylzh'];
            $arr['ylname'] = $value['ylname'];
            $arr['yladdr'] = $value['yladdr'];
            $arr['time'] = $value['time'];
            $arr['fktime'] = $value['fktime'];
            $arr['qrsktime'] = $value['qrsktime'];
            $arr['qrshtime'] = $value['qrshtime'];
            $arr['ordernumber'] = $value['ordernumber'];
            $arr['quxiaoinfo'] = $value['quxiaoinfo'];
            $arr['dqsj'] = $value['dqsj'];
            $arr['chengjiaojiage'] = $value['chengjiaojiage'];
            $data_arr[]=$arr;
        }

        if ($res->isPost()){

            if ($data_arr){

                echo json_encode(['zt'=>1,'msg'=>$data_arr]);

            }else{

                echo json_encode(['zt'=>0,'msg'=>'没有查询到任何订单']);

            }

        }else{

            echo json_encode(['zt'=>2,'msg'=>'error']);

        }
    }
    /*
     获取交易完成的订单
     *
     */
    public function Get_order_ok(){

        $res = Request::instance();

        $order_data = db('jiaoyibuylog')->where('oname|uname',$res->param('uname'))->where('oorderzt','>=',2)->order('id desc')->select();

        if ($res->isPost()){

            if ($order_data){

                echo json_encode(['zt'=>1,'msg'=>$order_data]);

            }else{

                echo json_encode(['zt'=>0,'msg'=>'没有查询到任何订单']);

            }

        }else{

            echo json_encode(['zt'=>2,'msg'=>'error']);

        }

    }

}